<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 400px;
            height: 400px;
        }
    </style>
</head>

<body>
    <button id="btn">点击换色</button>
    <div id="color" style="background: #ff24ff;"></div>
    <script>
        function Color() {
            var r = parseInt(Math.random() * 256)
            var g = parseInt(Math.random() * 256)
            var b = parseInt(Math.random() * 256)
            var res = '#' + r.toString(16) + g.toString(16) + b.toString(16)
            console.log(res)
            return res
        }
        btn.onclick = function () {
            color.style.background = '' + Color()
        }
    </script>
</body>

</html>